package cn.leftsite.juc.pattern.future.callable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

/**
 * @author wangjinqiang
 * @date 2019-06-06
 */
public class FutureMain {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 构造FutureTask
        FutureTask<String> futureTask = new FutureTask<>(new RealData("a"));
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        executorService.submit(futureTask);

        System.out.println("请求完毕");

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(futureTask.get());

        executorService.shutdown();
    }
}
